package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.common.principle.UserPrinciple;
import com.tarena.lbs.content.pojo.param.ArticleActionParam;
import com.tarena.lbs.content.pojo.param.ArticleContentParam;
import com.tarena.lbs.content.pojo.query.ArticleQuery;
import com.tarena.lbs.content.pojo.vo.ArticleActionPageResultVO;
import com.tarena.lbs.content.pojo.vo.ArticleVO;
import com.tarena.lbs.content.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * 文章业务模块接口
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Tag(name = "文章相关功能接口")
public class ArticleController {
    private final ArticleService articleService;

    @Operation(summary = "文章分页列表查询")
    @GetMapping("/admin/content/article/list")
    public Result<PageResult<ArticleVO>> pageList(@ModelAttribute ArticleQuery articleQuery)
        throws BusinessException{
        return new Result<>(articleService.articleList(articleQuery));
    }


    @Operation(summary = "文章保存")
    @PostMapping("/admin/content/article/insert")
    public Result<Void> addArticle(@RequestBody ArticleContentParam param)
        throws BusinessException{
        articleService.addArticle(param);
        return Result.success();
    }


    @Operation(summary = "文章标签集合")
    @GetMapping("/admin/content/article/getArticleLabel")
    public Result<Set<String>> articleLabels(@ModelAttribute ArticleQuery articleQuery) throws BusinessException {
        return new Result<>(articleService.articleLabels(articleQuery));
    }


    @Operation(summary = "文章详情")
    @GetMapping("/admin/content/article/get")
    public Result<ArticleVO> articleDetail(Integer id)throws BusinessException{
        return new Result<>(articleService.articleDetail(id));
    }


    @Operation(summary = "用户行为记录")
    @PostMapping("/admin/content/article/behavior")
    public Result<Void> articleBehavior(@RequestBody ArticleActionParam param)
        throws BusinessException{
        articleService.saveBehavior(param);
        return Result.success();
    }


    @Operation(summary = "查询已经点赞 收藏 访问过的文章")
    @GetMapping("admin/content/article/getBehaviorList")
    public Result<ArticleActionPageResultVO> getBehaviorLists(@ModelAttribute ArticleQuery query)
        throws BusinessException{
        return new Result<>(articleService.behaviorLists(query));
    }
}
